<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="com.sinodata.bsm.center.bean.ResBean"%>
<%@page import="net.sf.json.*"%>
<%@page import="com.sinodata.bsm.common.vo.Res"%>
<%@page import="com.sinodata.bsm.center.cache.PropertyValueCache"%>
<%@page import="org.springframework.beans.factory.annotation.Autowired"%>
<%@page import="com.sinodata.bsm.center.bean.PropertyBean"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
	Long resid = Long.parseLong(request.getParameter("id"));
	ResBean[] resBean = ResBean.get(resid).childrenByType(Long.parseLong("1208040000000"));
	StringBuffer resAppend = new StringBuffer("");
	for(int i=0;i<resBean.length;i++){
		Res res = resBean[i].res();
		resAppend.append((i==resBean.length-1)?res.getId():res.getId()+",");
	}
	StringBuffer netResAppend = new StringBuffer("");
	ResBean[] netResBean = ResBean.get(resid).childrenByType(Long.parseLong("1208030000000"));
	for(int i=0;i<netResBean.length;i++){
		Res res = netResBean[i].res();
		netResAppend.append((i==netResBean.length-1)?res.getId():res.getId()+",");
	}
	
	int vmLength = resBean.length;
 %>
<html>
  <head>
    <title>esx综合展现</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0"/>
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/table.jsp"%>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/style/default/bsm/sub_menu.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/style/default/bsm/perf/listPage.css" />
	
	<script type="text/javascript" src="${pageContext.request.contextPath}/resources/charts/FusionCharts.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/resources/charts/FusionCharts.jqueryplugin.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/common/Xslider.js"></script>
	
	<script type="text/javascript" src="${pageContext.request.contextPath}/jsp/performance/data/RTLine.js"></script>		
    <script type="text/javascript" src="${pageContext.request.contextPath}/jsp/performance/data/RTMemLine.js"></script>		
    <script type="text/javascript" src="${pageContext.request.contextPath}/jsp/performance/data/RTLED.js"></script>		
    <script type="text/javascript" src="${pageContext.request.contextPath}/jsp/performance/data/RTMemLed.js"></script>	
    
    <script type="text/javascript">
    
    	var uptimeColChart;
    	var fsColChartc;
    	function initBaseInfo(){
    		//基本信息
			$.ajax({
				url : 'real-time!getBaseInfo.action', // 
				type : 'POST',
				dataType : "json",
				data : {
					resId :<%=resid %>,
					propIds:'attr_110801000000001,attr_110801000000002,attr_110801000000003,attr_110801000000004,attr_110800000000001,attr_110800000000002'
				},
				success : function(data) {
					$('#attr_110801000000001').text(data.attr_110801000000001);
					$('#attr_110801000000002').text(data.attr_110801000000002);
					$('#attr_110801000000003').text(data.attr_110801000000003);
					$('#attr_110801000000004').text(data.attr_110801000000004);
					$('#attr_110800000000001').text(data.attr_110800000000001);
					var attr_110800000000002 = data.attr_110800000000002;
					$('#attr_110800000000002').text(attr_110800000000002.substring(0,attr_110800000000002.length-8));
					$('#resIp').text(data.ip);
				}
			});
			
			
			 //平均负载柱图
			$.ajax({
				url : 'real-time!get2ColumnPropChart.action', // 
				type : 'POST',
				dataType : "json",
				data : {
					resId :<%=resid %>,
					propIds:'110801000000001,110801000000002,110801000000003',
					namealias:'一分钟,五分钟,十五分钟'
				},
				success : function(data) {
					if(typeof uptimeColChart == undefined || uptimeColChart == null){
						 uptimeColChart =  new FusionCharts( "${pageContext.request.contextPath}/resources/charts/Column2D.swf","uptimeColChart11", "100%", "130", "0", "1" );
					}
					uptimeColChart.setJSONData(data);
					uptimeColChart.render("uptimeDiv");
				}
			});
			
			//文件系统
			if(typeof fsColChartc == undefined || fsColChartc == null){
				fsColChartc =  new FusionCharts( "${pageContext.request.contextPath}/resources/charts/Column2D.swf","fsColChart11", "100%", "130", "0", "1");
			}
			$.ajax({
				url : 'real-time!get2ColumnChart.action', // 
				type : 'POST',
				dataType : "json",
				data : {
					resId :<%=resid %>,
					detail:0,
					childType:'1208010000000',
					propIds:'120801000000001',
					top:'3',
					unit:'G'
				},
				success : function(data) {
					data.chart.formatNumberScale="0";
					$.each(data.data,function(index,ob){
						var val =ob.value/1024;
						ob.value= Math.round(val*Math.pow(10, 2))/Math.pow(10, 2);
					});
					fsColChartc.setJSONData(data);
					fsColChartc.render("fsColChart");
					
					//FusionCharts("fsColChart11").formatNumberScale="0";
				}
			});
    	}
    	
    	var  cpuVRealLed;
		var  cpuHisLine;
		var  memoryVRealLed	;
		var  memoryHisLine;
		function initRealTimeChart(){
			if(typeof cpuVRealLed ==undefined || cpuVRealLed == null){
				 cpuVRealLed =  new FusionCharts("${pageContext.request.contextPath}/resources/charts/VLED.swf", "cpuVled11", "100%", "130", "0", "1" );
	   			 cpuVRealLed.setXMLData(RTString);
       			 cpuVRealLed.render("cpuVReal");
       			 
       			 //CPU各指标值柱图
		         cpuHisLine =  new FusionCharts("${pageContext.request.contextPath}/resources/charts/RealTimeLine.swf", "cpuHisLine11", "300", "130", "0", "1" );
		         cpuHisLine.setXMLData(RTCpuHisString);
		         cpuHisLine.render("cpuHis");
		         
		         
		          //内存LED图
		         memoryVRealLed =  new FusionCharts("${pageContext.request.contextPath}/resources/charts/VLED.swf", "messmoryVled11", "100%", "130", "0", "1" );
		         memoryVRealLed.setXMLData(RTMemString);
		         memoryVRealLed.render("memoryVReal");
		        
		         //内存实时线图
		       	 memoryHisLine =  new FusionCharts("${pageContext.request.contextPath}/resources/charts/RealTimeLine.swf", "memoryHisLine11", "300", "130", "0", "1" );
		       	 memoryHisLine.setXMLData(RTMemHisString);
		         memoryHisLine.render("memoryhis");
			}
		}
		
		function freshMemData(){
			var cpuVLEDV = getChartFromId("cpuVled11");
			var cpuHisLineV = getChartFromId("cpuHisLine11");
			var memHisLineV = getChartFromId("memoryHisLine11");
			var memVLEDV = getChartFromId("messmoryVled11");
			
			 var currDate = new Date();
			 var label= currDate.getHours() + ":" + currDate.getMinutes() + ":" + currDate.getSeconds();
			 //cpu
	       $.ajax({
				url : 'real-time!getRealTimeVal.action', 
				type : 'POST',
				dataType : "json",
				data : {
					resId :<%=resid %>,
					propid:'110801000000004'
				},
				success : function(data) {
					var strData = "&label=" + label + "&value=" + data;
					cpuVLEDV.feedData("&value=" + data);
					cpuHisLineV.feedData(strData);
				}
			});
			
			
			 //内存
		    $.ajax({
				url : 'real-time!getRealTimeVal.action',  
				type : 'POST',
				dataType : "json",
				data : {
					resId :<%=resid %>,
					propid:'110801000000006'
				},
				success : function(data) {
					var strData = "&label=" + label + "&value=" + data;
					memHisLineV.feedData(strData);
					memVLEDV.feedData("&value=" + data);
				}
			 });
		}
		
		//虚拟机信息
		function vmInit(){
			var tabTbody = $('#vmValue table tbody');
			tabTbody.html('');
			var vmList = $('#vmList thead tr th');
			$.ajax({
					url : 'real-time!getResPropValue.action', 
					type : 'POST',
					dataType : "json",
					data : {
						resId :'<%=resAppend.toString() %>',
						propid:'120804000000001,120804000000002,120804000000003'
					},
					success : function(data) {
						
						$.each(data,function(index,ob){
							var trHtml = "<tr class='"+((index%2)==0?'odd':'even')+"' _DT_RowIndex='"+index+"'>"+
							"<td width='"+$(vmList[0]).width()+"'>"+ob.name+"</td>" +
							"<td width='"+$(vmList[1]).width()+"'><img src='${pageContext.request.contextPath}/style/default/bsm/images/VM"+(ob.runStatu==null?'none':ob.runStatu)+".png' title='"+(ob.runStatu==null?'?':ob.runStatu)+"' /></td>"+
							"<td width='"+$(vmList[2]).width()+"'>"+(ob.cpuCount==null?0:ob.cpuCount)+"</td>"+
							"<td width='"+$(vmList[3]).width()+"' >"+(ob.memorySize==null?0:ob.memorySize)+"</td></tr>";
							$(trHtml).appendTo(tabTbody);
						});
						
					}
				});
		}
		
		//网卡发送包数据初始化
		var netColChart1;
		function initNetworkData(){
			if(typeof netColChart1 == undefined || netColChart1 == null){
			 netColChart1 =  new FusionCharts( "${pageContext.request.contextPath}/resources/charts/MSSpline.swf?ChartNoDataText=没有数据","netColChart11", "100%", "100%", "0", "1" );
		   }
		   
			  $.ajax({
				url : 'real-time!get2LineChart2.action', // 
				type : 'POST',
				dataType : "json",
				data : {
					resId :'<%=netResAppend.toString() %>',
					propIds:'120803000000001,120803000000002'
				},
				success : function(data) {
					netColChart1.setJSONData(data);
					netColChart1.render("netColChart");
				}
			});
		}
    
    	$(document).ready(function(){
    		initBaseInfo();
    		initRealTimeChart();
			vmInit();
			initNetworkData();
			    		
    		//CPU 内存 每5S刷新一次
		    setInterval('freshMemData()',5000);
		    setInterval('initBaseInfo()',60000);
		    setInterval('vmInit()',60000);
    	});
    </script>
  </head>
  
  <body>
	<div class="column">
		<div class="col-main">
			<!-- baseInfo begin -->
			<div class="col-l-extra h-400">
				<h2 class="title-h2 m-0">基本信息</h2>
				<ul class="col-l-ul">
					<li>
						<span class="col-l-ul-l" >主机类型:</span>
						<span class="col-l-ul-r" ><img  width="16px" height="16px" src="${pageContext.request.contextPath}/style/default/bsm/perf/images/VMware_logo.png" />&nbsp;&nbsp;VMware ESX</span>
					</li>
					<li>
						<span class="col-l-ul-l" >IP:</span>
						<span class="col-l-ul-r" id="resIp" ></span>
					</li>
					<li>
						<span class="col-l-ul-l" >主机名称:</span>
						<span class="col-l-ul-r" id="attr_110800000000001" ></span>
					</li>
					<li>
						<span class="col-l-ul-l" >主机描述:</span>
						<span class="col-l-ul-r" id="attr_110800000000002" ></span>
					</li>
					<li>
						<span class="col-l-ul-l" >物理CPU个数:</span>
						<span class="col-l-ul-r" id="attr_110801000000001" ></span>
					</li>
					<li>
						<span class="col-l-ul-l" >CPU核数:</span>
						<span class="col-l-ul-r" id="attr_110801000000002" ></span>
					</li>
					<li>
						<span class="col-l-ul-l" >物理内存大小:</span>
						<span class="col-l-ul-r" id="attr_110801000000003" ></span>
					</li>
					<li>
						<span class="col-l-ul-l" >电源容量:</span>
						<span class="col-l-ul-r" id="attr_110801000000004" ></span>
					</li>
					<li>
						<span class="col-l-ul-l" >虚拟机个数:</span>
						<span class="col-l-ul-r"  ><%=vmLength  %></span>
					</li>
				</ul>
			</div>
			<!-- baseInfo end -->
			<!-- 平均负载 使用率 begin -->
			<div class="col-r-main">
				<div class="col-v-rate-extra" >
				<h2 class="title-h2 m-0">平均负载</h2>
					<div id="uptimeDiv"></div>
				</div>
				
				<div class="col-v-rate-extra f-r">
				<h2 class="title-h2 m-0">CPU使用率</h2>
				  <div id="cpuVReal" style="width:80px;height:180px; float:left;overflow:hidden;clear:none;  margin-left:1px;"></div>
				   <div id="cpuHis"  style="width:180px;height:180px;float:left;clear:none; background:#eee;"></div>
			    </div>
			    
			    <div class="col-v-rate-extra">
		            <h2 class="title-h2 m-0"> 文件系统使用大小 TOP3</h2>
			       <div id="fsColChart"></div>
			    </div>
			    
			    <div class="col-v-rate-extra f-r">
				<h2 class="title-h2 m-0"> 内存使用率</h2>
				   <div id="memoryVReal" style="width:80px;height:180px; float:left;overflow:hidden;clear:none; background:#ccc; margin-left:1px;"></div>
				   <div id="memoryhis"  style="width:180px;height:180px;float:left;clear:none; background:#eee;"></div>
			    </div>
			</div>
			<!-- 内存使用率使用率 end -->
		</div>
	</div>
	
	<div class="column">
		<div class="col-main" >
			<div class="col-net-main " >
				<h2 class="title-h2 m-0">虚拟机状态</h2>
				<table id="vmList" width="100%" cellpadding="0" cellspacing="0" border="0" class="display" >
					<thead>
						<tr>
							<th>资源名称</th>
							<th>运行状况</th>
							<th>CPU个数</th>
							<th>内存大小(MB)</th>
						</tr>
					</thead>
				</table>
				<div id="vmValue" style="overflow-y: scroll;height:74%;">
					<table width="100%" cellpadding="0" cellspacing="0" border="0" class="display" >
						<tbody></tbody>
					</table>
				</div>
			</div>
			
			<div class="col-net-main f-r w-48" >
				<h2 class="title-h2 m-0">网卡发送数据包数 [每秒发送的数据包数,每秒接收的数据包数]</h2>
				<div id="netColChart" class= "col-r-main h-150 w-100"></div>
			</div>
		</div>
	</div>
  </body>
</html>
